//
//  RCViewController.m
//  Clock
//
//  Created by ColorsOfWind on 2017/9/14.
//  Copyright © 2017年 qianfeng. All rights reserved.
//

#import "RCViewController.h"

@interface RCViewController ()
{
    UITextView * textView;
    UIButton * button;
}
@end

@implementation RCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(15 , 15 + 64, SCREEN_WIDTH - 30 , 30)];
    [self.view addSubview:label];
//    label.backgroundColor = [tool getColor:@"a9e72b"];
    label.text = _daytime;
    
    textView = [[UITextView alloc] initWithFrame:CGRectMake(15, 115, SCREEN_WIDTH - 30, 300)];
    
    NSString * richeng = [[NSUserDefaults standardUserDefaults] objectForKey:self.daytime];
    
    
    if (richeng) {
        textView.text = richeng;
    }
    
    [self.view addSubview:textView];
    
    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0, 0, 200, 44);
    button.center = CGPointMake(SCREEN_WIDTH / 2, CGRectGetMaxY(textView.frame) + 50);
    button.backgroundColor = [tool getColor:@"a9e72b"];
    [button setTitle:@"保 存" forState:UIControlStateNormal];
    [button addTarget: self action:@selector(saveDay) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)saveDay
{
    NSLog(@"Fire");
    
    if (textView.text) {
        [[NSUserDefaults standardUserDefaults] setObject:textView.text forKey:self.daytime];
        [MBProgressHUD showSuccess:@"日程设置成功"];
    }
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setUpNav];
}

- (void)setUpNav{
    
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]};
    /**
     * 添加左侧返回按钮
     */
    self.title = @"日程";
    
    self.navigationController.navigationBar.translucent = YES;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem.tintColor=[UIColor blackColor];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
